﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace KC.DataAccess.Admin.Migrations
{
    public partial class InitComAdminContext : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            #region Create Table
            migrationBuilder.EnsureSchema(
                name: "cDba");

            migrationBuilder.CreateTable(
                name: "tenant_DatabasePool",
                schema: "cDba",
                columns: table => new
                {
                    DatabasePoolId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Server = table.Column<string>(nullable: true),
                    Database = table.Column<string>(nullable: true),
                    UserName = table.Column<string>(nullable: true),
                    UserPasswordHash = table.Column<string>(nullable: true),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    TenantCount = table.Column<int>(nullable: false),
                    CanEdit = table.Column<bool>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    DatabaseType = table.Column<int>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_DatabasePool", x => x.DatabasePoolId);
                });

            migrationBuilder.CreateTable(
                name: "tenant_NoSqlPool",
                schema: "cDba",
                columns: table => new
                {
                    NoSqlPoolId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Endpoint = table.Column<string>(nullable: true),
                    AccessName = table.Column<string>(nullable: true),
                    AccessKeyPasswordHash = table.Column<string>(nullable: true),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    TenantCount = table.Column<int>(nullable: false),
                    CanEdit = table.Column<bool>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    NoSqlType = table.Column<int>(nullable: false),
                    Extend1 = table.Column<string>(nullable: true),
                    Extend2 = table.Column<string>(nullable: true),
                    Extend3 = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_NoSqlPool", x => x.NoSqlPoolId);
                });

            migrationBuilder.CreateTable(
                name: "tenant_QueuePool",
                schema: "cDba",
                columns: table => new
                {
                    QueuePoolId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Endpoint = table.Column<string>(nullable: true),
                    AccessName = table.Column<string>(nullable: true),
                    AccessKeyPasswordHash = table.Column<string>(nullable: true),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    TenantCount = table.Column<int>(nullable: false),
                    CanEdit = table.Column<bool>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    QueueType = table.Column<int>(nullable: false),
                    Extend1 = table.Column<string>(nullable: true),
                    Extend2 = table.Column<string>(nullable: true),
                    Extend3 = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_QueuePool", x => x.QueuePoolId);
                });

            migrationBuilder.CreateTable(
                name: "tenant_ServiceBusPool",
                schema: "cDba",
                columns: table => new
                {
                    ServiceBusPoolId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Endpoint = table.Column<string>(nullable: true),
                    AccessName = table.Column<string>(nullable: true),
                    AccessKeyPasswordHash = table.Column<string>(nullable: true),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    TenantCount = table.Column<int>(nullable: false),
                    CanEdit = table.Column<bool>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    DistributedMessageType = table.Column<int>(nullable: false),
                    Extend1 = table.Column<string>(nullable: true),
                    Extend2 = table.Column<string>(nullable: true),
                    Extend3 = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_ServiceBusPool", x => x.ServiceBusPoolId);
                });

            migrationBuilder.CreateTable(
                name: "tenant_StoragePool",
                schema: "cDba",
                columns: table => new
                {
                    StoragePoolId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Endpoint = table.Column<string>(nullable: true),
                    AccessName = table.Column<string>(nullable: true),
                    AccessKeyPasswordHash = table.Column<string>(nullable: true),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    TenantCount = table.Column<int>(nullable: false),
                    CanEdit = table.Column<bool>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    StorageType = table.Column<int>(nullable: false),
                    Extend1 = table.Column<string>(nullable: true),
                    Extend2 = table.Column<string>(nullable: true),
                    Extend3 = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_StoragePool", x => x.StoragePoolId);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserCallCharge",
                schema: "cDba",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    SessionId = table.Column<string>(nullable: true),
                    ChargeNbr = table.Column<string>(nullable: true),
                    DisplayNbr = table.Column<string>(nullable: true),
                    StartTime = table.Column<DateTime>(nullable: false),
                    EndTime = table.Column<DateTime>(nullable: false),
                    StarttimeCalled = table.Column<DateTime>(nullable: false),
                    BillSubtype = table.Column<string>(nullable: true),
                    Duration = table.Column<long>(nullable: false),
                    Points = table.Column<long>(nullable: false),
                    TenantName = table.Column<string>(nullable: true),
                    TenantDisplayName = table.Column<string>(nullable: true),
                    Caller = table.Column<string>(nullable: true),
                    CallerPhone = table.Column<string>(nullable: true),
                    BeCaller = table.Column<string>(nullable: true),
                    BeCallerPhone = table.Column<string>(nullable: true),
                    IsDownloadVoice = table.Column<bool>(nullable: false),
                    DownLoadUrl = table.Column<string>(nullable: true),
                    RecordUrl = table.Column<string>(nullable: true),
                    CallStatus = table.Column<int>(nullable: false),
                    CallLogResult = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserCallCharge", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserLoopTask",
                schema: "cDba",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    BusinessId = table.Column<string>(maxLength: 128, nullable: true),
                    Status = table.Column<string>(maxLength: 128, nullable: true),
                    Type = table.Column<string>(maxLength: 128, nullable: true),
                    TenantName = table.Column<string>(maxLength: 128, nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserLoopTask", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserServiceApplication",
                schema: "cDba",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: false),
                    TenantName = table.Column<string>(nullable: true),
                    TenantDisplayName = table.Column<string>(nullable: true),
                    ServiceType = table.Column<int>(nullable: false),
                    AppStatus = table.Column<int>(nullable: false),
                    WorkFlowStatus = table.Column<int>(nullable: false),
                    OperatorId = table.Column<string>(nullable: true),
                    OperatorDisplayName = table.Column<string>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserServiceApplication", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUser",
                schema: "cDba",
                columns: table => new
                {
                    TenantId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    TenantName = table.Column<string>(nullable: true),
                    TenantDisplayName = table.Column<string>(nullable: true),
                    TenantSignature = table.Column<string>(nullable: true),
                    TenantType = table.Column<int>(nullable: false),
                    Version = table.Column<int>(nullable: false),
                    CloudType = table.Column<int>(nullable: false),
                    PrivateEncryptKey = table.Column<string>(nullable: true),
                    DatabaseType = table.Column<int>(nullable: false),
                    Server = table.Column<string>(nullable: true),
                    Database = table.Column<string>(nullable: true),
                    DatabasePasswordHash = table.Column<string>(nullable: true),
                    StorageType = table.Column<int>(nullable: false),
                    StorageEndpoint = table.Column<string>(nullable: true),
                    StorageAccessName = table.Column<string>(nullable: true),
                    StorageAccessKeyPasswordHash = table.Column<string>(nullable: true),
                    QueueType = table.Column<int>(nullable: false),
                    QueueEndpoint = table.Column<string>(nullable: true),
                    QueueAccessName = table.Column<string>(nullable: true),
                    QueueAccessKeyPasswordHash = table.Column<string>(nullable: true),
                    NoSqlType = table.Column<int>(nullable: false),
                    NoSqlEndpoint = table.Column<string>(nullable: true),
                    NoSqlAccessName = table.Column<string>(nullable: true),
                    NoSqlAccessKeyPasswordHash = table.Column<string>(nullable: true),
                    DistributedMessageType = table.Column<int>(nullable: false),
                    ServiceBusEndpoint = table.Column<string>(nullable: true),
                    ServiceBusAccessName = table.Column<string>(nullable: true),
                    ServiceBusAccessKeyPasswordHash = table.Column<string>(nullable: true),
                    ContactName = table.Column<string>(nullable: true),
                    ContactEmail = table.Column<string>(nullable: true),
                    ContactPhone = table.Column<string>(nullable: true),
                    EnableEmail = table.Column<bool>(nullable: false),
                    EnableSms = table.Column<bool>(nullable: false),
                    EnableCallCenter = table.Column<bool>(nullable: false),
                    EnableWeixin = table.Column<bool>(nullable: false),
                    EnablePayment = table.Column<bool>(nullable: false),
                    EnableLogistics = table.Column<bool>(nullable: false),
                    EnableId5 = table.Column<bool>(nullable: false),
                    NickName = table.Column<string>(nullable: true),
                    NickNameLastModifyDate = table.Column<DateTime>(nullable: true),
                    OwnDomainName = table.Column<string>(nullable: true),
                    OwnDomainLevel = table.Column<int>(nullable: false),
                    PasswordExpiredTime = table.Column<DateTime>(nullable: true),
                    CanEdit = table.Column<bool>(nullable: false),
                    ReferenceId = table.Column<string>(nullable: true),
                    DatabasePoolId = table.Column<int>(nullable: false),
                    StoragePoolId = table.Column<int>(nullable: true),
                    QueuePoolId = table.Column<int>(nullable: true),
                    NoSqlPoolId = table.Column<int>(nullable: true),
                    ServiceBusPoolId = table.Column<int>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    CreatedBy = table.Column<string>(nullable: true),
                    CreatedDate = table.Column<DateTime>(nullable: false),
                    ModifiedBy = table.Column<string>(nullable: true),
                    ModifiedDate = table.Column<DateTime>(nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUser", x => x.TenantId);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUser_tenant_DatabasePool_DatabasePoolId",
                        column: x => x.DatabasePoolId,
                        principalSchema: "cDba",
                        principalTable: "tenant_DatabasePool",
                        principalColumn: "DatabasePoolId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUser_tenant_NoSqlPool_NoSqlPoolId",
                        column: x => x.NoSqlPoolId,
                        principalSchema: "cDba",
                        principalTable: "tenant_NoSqlPool",
                        principalColumn: "NoSqlPoolId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUser_tenant_QueuePool_QueuePoolId",
                        column: x => x.QueuePoolId,
                        principalSchema: "cDba",
                        principalTable: "tenant_QueuePool",
                        principalColumn: "QueuePoolId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUser_tenant_ServiceBusPool_ServiceBusPoolId",
                        column: x => x.ServiceBusPoolId,
                        principalSchema: "cDba",
                        principalTable: "tenant_ServiceBusPool",
                        principalColumn: "ServiceBusPoolId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUser_tenant_StoragePool_StoragePoolId",
                        column: x => x.StoragePoolId,
                        principalSchema: "cDba",
                        principalTable: "tenant_StoragePool",
                        principalColumn: "StoragePoolId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserApplication",
                schema: "cDba",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ApplicationId = table.Column<Guid>(nullable: false),
                    ApplicationName = table.Column<string>(nullable: true),
                    DomainName = table.Column<string>(nullable: true),
                    AppStatus = table.Column<int>(nullable: false),
                    WebSiteName = table.Column<string>(maxLength: 128, nullable: true),
                    TenantId = table.Column<int>(nullable: false),
                    Version = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserApplication", x => x.Id);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUserApplication_tenant_TenantUser_TenantId",
                        column: x => x.TenantId,
                        principalSchema: "cDba",
                        principalTable: "tenant_TenantUser",
                        principalColumn: "TenantId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserOpenAppErrorLog",
                schema: "cDba",
                columns: table => new
                {
                    ProcessLogId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Type = table.Column<int>(nullable: false),
                    OperatorId = table.Column<string>(nullable: true),
                    Operator = table.Column<string>(maxLength: 50, nullable: true),
                    OperateDate = table.Column<DateTime>(nullable: false),
                    Remark = table.Column<string>(nullable: true),
                    TenantDisplayName = table.Column<string>(nullable: true),
                    OpenServerType = table.Column<int>(nullable: false),
                    TenantId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserOpenAppErrorLog", x => x.ProcessLogId);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUserOpenAppErrorLog_tenant_TenantUser_TenantId",
                        column: x => x.TenantId,
                        principalSchema: "cDba",
                        principalTable: "tenant_TenantUser",
                        principalColumn: "TenantId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserAppModule",
                schema: "cDba",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ModuleId = table.Column<Guid>(nullable: false),
                    ModuleName = table.Column<string>(nullable: true),
                    Description = table.Column<string>(nullable: true),
                    AssemblyName = table.Column<string>(nullable: true),
                    ApplicationId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserAppModule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUserAppModule_tenant_TenantUserApplication_ApplicationId",
                        column: x => x.ApplicationId,
                        principalSchema: "cDba",
                        principalTable: "tenant_TenantUserApplication",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tenant_TenantUserOperationLog",
                schema: "cDba",
                columns: table => new
                {
                    ProcessLogId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Type = table.Column<int>(nullable: false),
                    OperatorId = table.Column<string>(nullable: true),
                    Operator = table.Column<string>(maxLength: 50, nullable: true),
                    OperateDate = table.Column<DateTime>(nullable: false),
                    Remark = table.Column<string>(nullable: true),
                    ApplicationId = table.Column<Guid>(nullable: false),
                    ApplicationName = table.Column<string>(maxLength: 128, nullable: true),
                    DomainName = table.Column<string>(maxLength: 128, nullable: true),
                    AppStatus = table.Column<int>(nullable: false),
                    TenantName = table.Column<string>(nullable: true),
                    TenantDisplayName = table.Column<string>(nullable: true),
                    LogType = table.Column<int>(nullable: false),
                    AdditionalInfo = table.Column<string>(nullable: true),
                    TenantUserApplicationId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_TenantUserOperationLog", x => x.ProcessLogId);
                    table.ForeignKey(
                        name: "FK_tenant_TenantUserOperationLog_tenant_TenantUserApplication_TenantUserApplicationId",
                        column: x => x.TenantUserApplicationId,
                        principalSchema: "cDba",
                        principalTable: "tenant_TenantUserApplication",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUser_DatabasePoolId",
                schema: "cDba",
                table: "tenant_TenantUser",
                column: "DatabasePoolId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUser_NoSqlPoolId",
                schema: "cDba",
                table: "tenant_TenantUser",
                column: "NoSqlPoolId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUser_QueuePoolId",
                schema: "cDba",
                table: "tenant_TenantUser",
                column: "QueuePoolId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUser_ServiceBusPoolId",
                schema: "cDba",
                table: "tenant_TenantUser",
                column: "ServiceBusPoolId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUser_StoragePoolId",
                schema: "cDba",
                table: "tenant_TenantUser",
                column: "StoragePoolId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUserApplication_TenantId",
                schema: "cDba",
                table: "tenant_TenantUserApplication",
                column: "TenantId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUserAppModule_ApplicationId",
                schema: "cDba",
                table: "tenant_TenantUserAppModule",
                column: "ApplicationId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUserOpenAppErrorLog_TenantId",
                schema: "cDba",
                table: "tenant_TenantUserOpenAppErrorLog",
                column: "TenantId");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_TenantUserOperationLog_TenantUserApplicationId",
                schema: "cDba",
                table: "tenant_TenantUserOperationLog",
                column: "TenantUserApplicationId");
            #endregion

            #region Init Database Structure with sql: KC.DataAccess.Account

            var sqlBuilder = new System.Text.StringBuilder();
            var sqlStatements = KC.DataAccess.Admin.DataInitial.DBSqlInitializer.GetStructureSqlScript();
            foreach (var line in sqlStatements)
            {
                string sqlLine = line;
                if (line.Trim().ToUpper() == "GO")
                {
                    string sql = sqlBuilder.ToString();
                    if (!string.IsNullOrWhiteSpace(sql))
                        migrationBuilder.Sql(sql);
                    sqlBuilder.Clear();
                }
                else
                {
                    sqlBuilder.AppendLine(sqlLine);
                }
            }

            #endregion

            #region Insert data into Database with sql: KC.DataAccess.Account

            sqlBuilder = new System.Text.StringBuilder();
            sqlStatements = KC.DataAccess.Admin.DataInitial.DBSqlInitializer.GetInitialDataSqlScript();
            foreach (var line in sqlStatements)
            {
                string sqlLine = line;
                if (line.Trim().ToUpper() == "GO")
                {
                    string sql = sqlBuilder.ToString();
                    if (!string.IsNullOrWhiteSpace(sql))
                        migrationBuilder.Sql(sql);
                    sqlBuilder.Clear();
                }
                else
                {
                    sqlBuilder.AppendLine(sqlLine);
                }
            }

            #endregion
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "tenant_TenantUserAppModule",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserCallCharge",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserLoopTask",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserOpenAppErrorLog",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserOperationLog",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserServiceApplication",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUserApplication",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_TenantUser",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_DatabasePool",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_NoSqlPool",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_QueuePool",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_ServiceBusPool",
                schema: "cDba");

            migrationBuilder.DropTable(
                name: "tenant_StoragePool",
                schema: "cDba");
        }
    }
}
